package dao;

import hibernateUtils.HibernateUtil;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import beans.RecetaBean;

public class HibernateRecetaDAO {
	private static HibernateRecetaDAO instancia = null;
	private static SessionFactory sf = null;

	public static HibernateRecetaDAO getInstancia() {
		if (instancia == null) {
			sf = HibernateUtil.getSessionFactory();
			instancia = new HibernateRecetaDAO();
		}
		return instancia;
	}

	public void grabarReceta(RecetaBean receta) {
		Session sesion = sf.openSession();
		sesion.beginTransaction();
		sesion.persist(receta);
		sesion.flush();
		sesion.getTransaction().commit();
		sesion.close();
	}

	public RecetaBean buscarReceta(RecetaBean recetab) {
		Session session = sf.openSession();
		RecetaBean receta = (RecetaBean) session.get(RecetaBean.class,
				recetab.getId());
		session.close();
		return receta;
	}

}
